// 响应工具函数

import { ResponseCodes } from '../types/index.js'

/**
 * 成功响应
 */
const successResponse = (res, data = null, message = '操作成功') => {
  return res.status(ResponseCodes.SUCCESS).json({
    success: true,
    message,
    data
  })
}

/**
 * 创建成功响应
 */
const createdResponse = (res, data = null, message = '创建成功') => {
  return res.status(ResponseCodes.CREATED).json({
    success: true,
    message,
    data
  })
}

/**
 * 错误响应
 */
const errorResponse = (res, message = '操作失败', statusCode = ResponseCodes.BAD_REQUEST) => {
  return res.status(statusCode).json({
    success: false,
    message,
    error: true
  })
}

/**
 * 未授权响应
 */
const unauthorizedResponse = (res, message = '未授权访问') => {
  return errorResponse(res, message, ResponseCodes.UNAUTHORIZED)
}

/**
 * 禁止访问响应
 */
const forbiddenResponse = (res, message = '禁止访问') => {
  return errorResponse(res, message, ResponseCodes.FORBIDDEN)
}

/**
 * 未找到响应
 */
const notFoundResponse = (res, message = '资源未找到') => {
  return errorResponse(res, message, ResponseCodes.NOT_FOUND)
}

/**
 * 服务器错误响应
 */
const serverErrorResponse = (res, message = '服务器内部错误') => {
  return errorResponse(res, message, ResponseCodes.INTERNAL_ERROR)
}

export {
  successResponse,
  createdResponse,
  errorResponse,
  unauthorizedResponse,
  forbiddenResponse,
  notFoundResponse,
  serverErrorResponse
} 